import urllib.parse
import urllib.request
import json
url = "https://music.163.com/weapi/v1/resource/comments/A_PL_0_377095723?csrf_token="

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
}

data = {
    "params":"jcBcIuT6q5BR+Mj3cxRrY4N4iL90teIFxz1O6qQbf+pU0l98Kr+YHRtLAZdOLhGwujVLlKidSiwwuUH75BBKMhgb0QYm8ueqlmlZtJ7ed2MWNTrjHLEGsHbLi2anOw38qcY5nOlMFhH9f+mGmhF4SnK/VVGtIdLcHP1WWaaKn/ynYTvKt0F+vrVv7pQFA/QhDnJH+kMIblWFQU6f0jwbMVw4L5uiguEQsAy7jcIfTkg=",
    "encSecKey":"c5dd129f5400e162787dea4b6c814876cdc11760b09bd1a5a9a96ac0fd1c84f353f2a286ca5c3cef81479534d1d7abdd5232631585e3f8966d2cb279199cfb576a8cdf517d6e3bfd41f81aab60cd69ec19f87aa9020e4051216ba85bbdd3e6d1d688a8b30dc880d2d525d49735508ca37ba32a1ce3ba801ef38bca6a94be46a6",
}

data = urllib.parse.urlencode(data).encode()
# print(data)

#创建请求对象   默认data为None 说明是get请求
#如果你设置了 data=data 说明就是post请求

req = urllib.request.Request(url,headers=headers,data=data)

#获取返回的数据
response = urllib.request.urlopen(req)

content = response.read().decode()
print(content)

comments_list = json.loads(content)
print(comments_list)
hot_list = comments_list['comments']
for comments in hot_list:
    nick_name = comments['user']['nickname']
    content = comments['content']
    print(nick_name,":",content)

